package com.snakegame.repository;

import com.snakegame.entity.User;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.Optional;

@Repository
public interface UserRepository extends JpaRepository<User, Long> {
    Optional<User> findByUsername(String username);
    
    boolean existsByUsername(String username);
    
    @Query("SELECT u FROM User u ORDER BY u.highestScore DESC")
    java.util.List<User> findTopUsersByHighestScore();
    
    @Query("SELECT u FROM User u WHERE u.username LIKE %:keyword% ORDER BY u.highestScore DESC")
    java.util.List<User> searchUsersByUsername(@Param("keyword") String keyword);
}